import json
import os

class Db:
    def __init__(self):
        pass

    # 创建文件(存在则不创建)
    def create_json(self, name):
        if not os.path.exists(name):
            with open(name, 'a', encoding='utf-8') as f:
                t = []
                json.dump(t, f)

    # 从json文件中读出数据
    def json_read(self, name):
        with open(name, 'r', encoding='utf-8') as f:
            self.json_load = json.loads(f.read())


    # 向json文件中添加一个数据写入数据
    def json_insert(self, name, d):
        print(self.json_load)
        self.json_load.append(d)
        with open(name, 'w', encoding='utf-8') as f:
            json.dump(self.json_load, f)


    # 更新文件数据(给删除用, 删除文件直接给的是列表信息)
    def json_write(self, name, d):
        with open(name, 'w', encoding='utf-8') as f:
            json.dump(d, f)

db = Db()
